<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 2018/7/27
 * Time: 15:49
 */
namespace app\alipay\controller;

use app\common\model\Base;
use app\alipay\model\AddressManager;

class Address extends Base{

    private $mAddressManager;
    public function __construct()
    {
        parent::__construct();
        $this->mAddressManager = new AddressManager();
    }

    /**
     *
     * @api {get} /alipay/address/:id 读取支付宝账号
     * @apiDescription 支付宝-读取支付宝账号
     * @apiGroup alipay
     *
     *@apiParamExample {json} Request-Example:
     *     {
     *       "name": xxx，
     *       "amount": "xxx",
     *     }
     *
     * @apiSuccess {String} code 0 表示失败 1 表示成功.
     * @apiSuccess {String} msg 返回消息.
     * @apiSuccessExample {json} Success-Response:
     *     {
     *       "code": "1",
     *       "msg": "更新成功"
     *     }
     */
    public function read($id){
        $result = $this->mAddressManager->getAddress($id);
        if($result)
            echoJson(1, $result);
        else
            echoJson(0, "读取失败");
    }

    /**
     *
     * @api {put} /alipay/address/:id 更新支付宝账号
     * @apiDescription 支付宝-更新支付宝账号
     * @apiGroup alipay
     * @apiParam {string} [name] 支付宝账户名
     * @apiParam {string} [account] 支付宝账号
     *
     *@apiParamExample {json} Request-Example:
     *     {
     *       "name": xxx，
     *       "amount": "xxx",
     *     }
     *
     * @apiSuccess {String} code 0 表示失败 1 表示成功.
     * @apiSuccess {String} msg 返回消息.
     * @apiSuccessExample {json} Success-Response:
     *     {
     *       "code": "1",
     *       "msg": "更新成功"
     *     }
     */
    public function update($id){
        $name = $_GET["name"];
        $account = $_GET["account"];

        if($this->mAddressManager->setAddress($id,$name,$account)){
            echoJson(1, "更新成功");
        }else{
            echoJson(0, "更新失败");
        }
    }

}